﻿using ERP_RORZE.Properties;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ERP_RORZE_SYSTEM;

namespace ERP_RORZE
{
    public partial class DatabaseConnection : Form
    {
        private INISettings MySetting = new INISettings();

        public DatabaseConnection()
        {
            InitializeComponent();
        }

        private void DatabaseConnection_Load(object sender, EventArgs e)
        {                        
            this._ServerValue.Text = MySetting.server;
            this._UserValue.Text = MySetting.user;
            this._PasswordValue.Text = MySetting.password;
            this._DatabaseNameValue.Text = MySetting.database;
        }

        private void _TestConnection_Click(object sender, EventArgs e)
        {
            MySetting.server = this._ServerValue.Text;
            MySetting.user = this._UserValue.Text;
            MySetting.password = this._PasswordValue.Text;
            MySetting.database = this._DatabaseNameValue.Text;
            if (MySetting.CheckDatabaseConnection())
            {
                MessageBox.Show("Database connect sucessfully!");
            }
            else
            {
                MessageBox.Show("Database connect failed!");
            }            
        }

        private void _DatabaseConnectionOK_Click(object sender, EventArgs e)
        {
            MySetting.server = this._ServerValue.Text;
            MySetting.user = this._UserValue.Text;
            MySetting.password = this._PasswordValue.Text;
            MySetting.database = this._DatabaseNameValue.Text;
            if (MySetting.CheckDatabaseConnection())
            {
                MySetting.UpdateSetting();
                this.Dispose();
            }
            else
            {
                MessageBox.Show("Database connect failed!");
            }            
        }

        private void _DatabaseConnectionCancel_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
    }
}
